package com.wechat.back.controller;

import com.wechat.back.anno.OptLog;
import com.wechat.back.pojo.inform.NoticeData;
import com.wechat.back.pojo.inform.NoticeType;
import com.wechat.back.pojo.tools.Result;
import com.wechat.back.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Autowired NoticeService noticeService;

    @GetMapping("/notice-list")
    public Result<List<NoticeData>> noticeList() {
        List<NoticeData> noticeDataList =noticeService.noticeList();
        return Result.success(noticeDataList);
    }
    @GetMapping("/noticeType-list")
    public Result<List<NoticeType>> typeList() {
        List<NoticeType> noticeTypeList =noticeService.typeList();
        return Result.success(noticeTypeList);
    }

    @OptLog(optModule = "通知模块",optType = "添加", optDesc = "添加通知")
    @PostMapping("/add-notice")
    public Result addNotice(@RequestBody @Validated(NoticeData.Add.class)NoticeData noticeData){
        noticeService.addNotice(noticeData);
        return Result.success();
    }

    @OptLog(optModule = "通知模块",optType = "添加", optDesc = "添加通知类型")
    @PostMapping("/add-noticeType")
    public Result addType(@RequestBody @Validated(NoticeType.Add.class)NoticeType noticeType){
        noticeService.addType(noticeType);
        return Result.success();
    }

    @OptLog(optModule = "通知模块",optType = "修改", optDesc = "修改通知")
    @PutMapping("/update-notice")
    public Result updateNotice(@RequestBody @Validated(NoticeData.Update.class)NoticeData noticeData){
        noticeService.updateNotice(noticeData);
        return Result.success();
    }

    @OptLog(optModule = "通知模块",optType = "修改", optDesc = "修改通知类型")
    @PutMapping("/update-noticeType")
    public Result updateType(@RequestBody @Validated(NoticeType.Update.class)NoticeType noticeType){
        noticeService.updateType(noticeType);
        return Result.success();
    }

    @OptLog(optModule = "通知模块",optType = "删除", optDesc = "删除通知")
    @DeleteMapping("/delete-notice")
    public Result deleteNotice(Integer noticeId){
        noticeService.deleteNotice(noticeId);
        return Result.success();
    }

    @OptLog(optModule = "通知模块",optType = "删除", optDesc = "删除通知类型")
    @DeleteMapping("/delete-noticeType")
    public Result deleteType(Integer typeId){
        noticeService.deleteType(typeId);
        return Result.success();
    }
}
